<?php

namespace app\shop\behavior;

use think\Controller;
use think\Db;
use think\Cache;
use app\shop\model\InformationType as InformationTypeModel;


class GoodsType extends Controller
{
    /**
     * 网站底部列表
     */
    public function run()
    {
        //$this->redirect('Mobile/UserPort/index');
        // 实例化
        $informationType = InformationTypeModel::all();

        $types = get_cate($informationType, 11);

        Cache::set('foot_information', $types);

        $type_arr = Db::name('GoodsType')->where(['status' => 1])->field('id,parenTid,title')->select();

        $data = self::get_cate($type_arr);

        cache('menu',$data,86400);
    }


    // 多层递归
    function get_cate($arr, $fid = 0)
    {
        $newArr = array();
        foreach ($arr as $v) {
            if ($v["parenTid"] == $fid) {
                $newArr[] = array(
                    "id"    => $v['id'],
                    "title" => $v['title'],
                    "son"   => get_cate($arr, $v['id']),
                );
            }
        }
        return $newArr;
    }
}